package com.spring.resourceLoader;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;

import java.io.IOException;

/**
 * Created by wangyg on 2017/1/4.
 */
public class MoocResource implements ApplicationContextAware {

	private ApplicationContext applicationContext;
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext=applicationContext;
	}
	
	public void resource(){
		Resource resource = applicationContext.getResource("file:D:\\TempFiles\\IntellijIdea\\Pisum\\TestSpring\\src\\main\\resources\\config.txt");
		System.out.println(resource.getFilename());
		try {
			System.out.println(resource.contentLength());
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
